<?php require admin_tpl('header');?>

<div class="tab">
	<ul>
		<li><a href="?mod=comment" <?php if (empty($filter)) {echo 'class="on"';}?>>全部评论</a></li>
		<li><a href="?mod=comment&filter=unchk" <?php if ($filter=='unchk') {echo 'class="on"';}?>>待审核(<?=$uncknum?>)</a></li>
	</ul>
</div>

<div class="main">

<?php if ( $ac == 'list' ) { ?>
		<div class="search">
			<form name="search" method="get" action="admin.php">
			<input type="hidden" name="ac" value="list" />
			<input type="hidden" name="mod" value="<?php echo $mod?>" />
				<fieldset>
					<legend>评论查找</legend>
						关键字：
						<input type="text" name="keyword" size="15" value="<?php echo $keyword; ?>" />
						<input type="submit" name="s" class="button" value="开始查找" />
				</fieldset>
			</form>
		</div>
		<form name="update" method="post" action="?mod=comment">
			<table class="datalist" id="list" cellspacing="0">
				<tr>
					<th width="30" class="firstcol">选择</th>
					<th width="200">作者</th>
					<th>评论</th>
					<th width="250">所在</th>
				</tr>

				<?php
				if  ( $result ) {
				foreach ($result as $row) { ?>
				<tr id="row_<?php echo $row['id']?>" <?php echo ($row['status'] ? '' : 'class="highlight"');?>>
					<td align="center" valign="top"><input type="checkbox" name="id[]" value="<?php echo $row['id']?>" class="checkbox" /></td>
					<td valign="top">
					<span class="avatar">
					<?php avatar($row['email'])?>
					</span>
					<b><?php echo $row['author'];?></b>
					<p>
					<?php
					if ( $row['url'] ) {
						echo "<a href=\"{$row[url]}\" title=\"{$row[url]}\" target=\"_blank\">Url</a> | ";
					}
					if ( $row['email'] ) {
						echo "<a href=\"mailto:{$row[email]}\" title=\"{$row[email]}\">Email</a> | ";
					}
					if ( $row['ip'] ) {
						echo "<a href=\"#\" title=\"{$row[ip]}\">IP</a>";
					}
					?>
					</p>
					</td>
					<td valign="top">
						<div style="color:#666">发布于 <a href="<?php echo url('mod=post&id='.$row['postid'])?>#comment-<?php echo $row['id']?>" target="_blank" title="查看评论"><?php echo get_date($row['dateline']);?></a></div>
						<div id="c_<?php echo $row['id']?>" style="font-size:13px"><?php echo $row['content']?></div>
						<div class="row_action">
						<div class="admintools">
						<?php if ( check_perm('comment','check') ) { ?>
						<?php if ( $row['status'] == 1 ) { ?>
						<a href="?mod=comment&ac=nopass&id=<?php echo $row['id'];?>" style="color:#f60">驳回</a> |
						<?php } else { ?>
						<a href="?mod=comment&ac=pass&id=<?php echo $row['id'];?>" style="color:green">通过</a> |
						<?php } ?>
						<?php } ?>
						<?php if ( check_perm('comment','edit') ) { ?>
						<a href="?mod=comment&ac=edit&id=<?php echo $row['id'];?>">编辑</a> |
						<?php } ?>
						<?php if ( check_perm('comment','reply') ) { ?>
						<a href="?mod=comment&ac=reply&id=<?php echo $row['id'];?>">回复</a> |
						<?php } ?>
						<?php if ( check_perm('comment','del') ) { ?>
						<a href="?mod=comment&ac=delete&id=<?php echo $row['id']?>" style="color:#c00">删除</a>
						<?php } ?>
						</div>
						</div>
					</td>
					<td align="left" valign="top" style="color:#666">
					<a href="<?php echo url('mod=post&id='.$row['postid'])?>" target="_blank"><?php echo cut_str($row['title']) ?></a>
					<br />发表于 <?php echo get_date($row['posttime'])?>
					</td>
				</tr>
				<?php
					}
				} else {
					echo '<tr><td colspan="10">暂无记录...</td></tr>';
				}
				?>
				<tr>
					<td align="center">
					<input type="checkbox" class="checkbox" value="1" name="chkall" id="chkall" onclick="check_all(this)" /></td>
					<td colspan="5">
					<label for="chkall">全选</label>
					<?php if ( check_perm('comment','check') ) { ?>
					<input type="radio" name="ac" value="pass" id="ac_pass" class="radio" checked /><label for="ac_pass">通过</label>
					<input type="radio" name="ac" value="nopass" id="ac_nopass" class="radio" /><label for="ac_nopass">驳回</label>
					<?php } ?>
					<?php if ( check_perm('comment','del') ) { ?>
					<input type="radio" name="ac" value="delete" id="ac_delete" class="radio" /><label for="ac_delete">删除</label>
					<?php } ?>
					<input type="submit" class="submit" value="执行操作"/>
					</td>
				</tr>
				<tr>
					<td colspan="10"><?php echo multipage()?></td>
				</tr>
			</table>
		</form>
<?php } elseif ( $ac == 'edit' ) { ?>

	<form name="save" method="post" action="?mod=comment&ac=edit">
	<input type="hidden" name="dosubmit" value="yes" />
	<input type="hidden" name="refer" value="<?php echo $_USER['refer']?>" />
	<input type="hidden" name="id" value="<?php echo $result['id']?>" />
	<table class="sub panel" cellspacing="0">
		<tr>
			<th colspan="2" class="title">编辑评论</th>
		</tr>
		<tr>
			<td>作者：</td>
			<td><input type="text" name="comment[author]" size="50" value="<?php echo $result['author']?>" /></td>
		</tr>
		<tr>
			<td>邮件：</td>
			<td><input type="text" name="comment[email]" size="50" value="<?php echo $result['email']?>" /></td>
		</tr>
		<tr>
			<td>网址：</td>
			<td><input type="text" name="comment[url]" size="50" value="<?php echo $result['url']?>" /></td>
		</tr>
		<tr>
			<td>内容：</td>
			<td>
			<textarea name="comment[content]" rows="5" cols="100%"><?php echo $result['content']?></textarea>
			</td>
		</tr>
		<tr>
			<td></td>
			<td>
			<input type="submit" value="更新评论" class="button" />
			<input type="button" value="取消返回" class="button" onclick="history.back()" />
			</td>
		</tr>
	</table>
	</form>

<?php } elseif ( $ac == 'reply' ) { ?>

	<form name="save" method="post" action="?mod=comment&ac=reply">
	<input type="hidden" name="dosubmit" value="yes" />
	<input type="hidden" name="postid" value="<?php echo $comment['postid']?>" />
	<input type="hidden" name="replyid" value="<?php echo $comment['id']?>" />
	<table class="sub panel" cellspacing="0">
		<tr>
			<th colspan="2" class="title">回复评论</th>
		</tr>
		<tr>
			<td width="100">作者：</td>
			<td><?php echo $comment['author']?></td>
		</tr>
		<tr>
			<td>内容：</td>
			<td>
			<?php echo $comment['content']?>
			</td>
		</tr>
		<tr>
			<td>回复：</td>
			<td>
			<textarea name="content" id="content" rows="5" cols="100%"><?php echo $content;?></textarea>
			</td>
		</tr>
		<tr>
			<td></td>
			<td>
			<input type="submit" value="提交评论" class="button" />
			<input type="button" value="取消返回" class="button" onclick="history.back()" />
			</td>
		</tr>
	</table>
	</form>

<?php } ?>

</div>

<script type="text/javascript">
$( function() {
	$('#list tr').each( function() {
		$(this).mouseover( function() {
			$(this).children().find('.admintools').show();
		});
		$(this).mouseout( function() {
			$(this).children().find('.admintools').hide();
		});
	});
});
</script>

<?php require admin_tpl('footer');?>